package com.demomaster.quickcompat.view.adapter;

import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public abstract class QuickViewHolder extends RecyclerView.ViewHolder {
    int position;
    public QuickViewHolder(@NonNull View itemView) {
        super(itemView);
    }
    public void onBind(int position){

    }
    public void onBind(int position, List data){

    }
    public void onUnbind(){

    }

    public static boolean isActivityDestroyed(Context context) {
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                return activity.isFinishing() || activity.isDestroyed();
            } else {
                return activity.isFinishing();
            }
        }
        return false;
    }

    public <VH extends QuickViewHolder> void bind(VH holder, int position){
        this.position = position;

    }
    //public abstract <VH extends QuickViewHolder> void bind(VH holder);

//    public static boolean isFragmentAttachedToDestroyedActivity(Context context) {
//        if (context instanceof Fragment) {
//            Fragment fragment = (Fragment) context;
//            if (fragment.getActivity() != null) {
//                return fragment.getActivity().isFinishing() || fragment.getActivity().isDestroyed();
//            }
//        }
//        return false;
//    }

}
